<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>砭石</title>
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/index.css">
</head>

<body>
    <div class="box">
        <div class="content">
            <div class="image">
                <img src="./images/logoBlack.png" alt="">
            </div>
            <h2>后台管理系统</h2>
            <form action="">
                <div>
                    <label for="name">用户名:</label><input type="text" id="name">
                </div>
                <div>
                    <label for="psd">密 码:</label><input type="password" id="psd">
                </div>
            </form>
            <button class="btn">登录</button>
        </div>
    </div>
    <script src="./js/jquery-3.3.1.js"></script>
    <script>
        $(function () {
            $.ajaxSetup({
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                }
            });
            document.onkeydown = function (e) { // 回车提交表单
                // 兼容FF和IE和Opera
                var theEvent = window.event || e;
                var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
                if (code == 13) {
                    $(".btn").click();
                }
            }
            $(".btn").on('click', function () {
                $.ajax({
                    type: "POST",
                    url: 'http://bianshi.hebinqunyan.com/login/admin',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        username: $("#name").val(),
                        password: $("#psd").val()
                    },
                }).done(function (data) {
                    console.log(data);
                    if (data.success) {
                        window.location.href = 'html/home.html'; // 调到获取接口
                    } else {
                        alert(data.msg);
                    }
                });

            });
        })
    </script>
</body>

</html>